<template>

  用户名：<input type="text" v-model="userName"/><br/>
  密码：<input type="password" v-model="password"/><br/>
  userName:{{userName}}<br/>
  password:{{password}}
  <button @click="login">登录</button>

  <button @click="userList">展示用户列表</button>

</template>

<script setup>
import axios from "axios";
import {ref} from 'vue';

let userName = ref("")
let password = ref("")

let token = ''

function login(){
  // 向给定ID的用户发起请求
  axios.get('http://localhost:8081/login?userName='+userName.value+'&password='+password.value)
      .then(function (response) {
        // 处理成功情况
        console.log(response.data);
        token = response.data
        console.log(token)
      })
      .catch(function (error) {
        // 处理错误情况
        console.log('error->',error);
      })
}

function userList(){
  console.log(token)
  axios.get('http://localhost:8081/user/list?token='+token)
      .then(function (response) {
        // 处理成功情况
        console.log(response);
      })
      .catch(function (error) {
        // 处理错误情况
        console.log(error);
      })
}

</script>
